<?php
namespace Home\Controller;
use Think\Controller;
class ChangePasswordController extends Controller {
    public function index(){
        $uid=session('uid');
        $upic=M('users')->where(array("uid"=>$uid))->select();
        $password = M("users")->where(array("uid" => $uid))->select();
         /*dump($password);*/
        $this->password=$password;
        if(!$uid)
        {$this->error('登录已过期!',U("Home/Login/index"));}
        elseif($password){
            $this->assign('list', $password);
            $this->assign('upic', $upic);
            $this->display();
        }
        else{ $this->error('获取失败!', U("Home/Personal/index"));}
    }


    public function reset(){
        $password = trim(I('post.password'));
        $newpassword = trim(I('post.newpassword'));
        $okpassword = trim(I('post.okpassword'));

        $a=M("users");
        $pwd = $a-> where(array('password'=>$password)) -> find();
        if(!$pwd){
            $this->error('原密码错误!',U("Home/ChangePassword/index"));
        }
        elseif($newpassword==$password)
        {
            $this->error('新旧密码相同!',U("Home/ChangePassword/index"));
        }
        elseif ($newpassword!=$okpassword){
            $this->error('两次密码不一致!',U("Home/ChangePassword/index"));
        }
        else{
            $a->password=$newpassword;
            $a->save();
            $this->success('修改成功',U("Home/Personal/index"));
        }

        
        
        
        
    }
    }